package com.atlin.project.job.cycle;

import com.atlin.project.service.TaskListService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author atlin
 * @description 同步缓存 维护任务状态
 * @createDate 2024/11/8 9:23
 */
@Component
@Slf4j
public class TaskListOperation {

    @Resource
    private TaskListService taskListService;

    /**
     * 每天 00:10 05:00 12:00
     */
    @Scheduled(cron = "0 10 0 * * ?")
    @Scheduled(cron = "0 0 5 * * ?")
    @Scheduled(cron = "0 0 12 * * ?")
    public void syncTaskListCache() {
        // 查询近 5 分钟内的数据
        log.info("TaskListOperation syncTaskListCache execute start");
        try {
            taskListService.buildTaskListCache();
            log.info("TaskListOperation syncTaskListCache execute end");
        } catch (Exception e) {
            log.error("TaskListOperation syncTaskListCache execute fail ", e);
        }
    }

    /**
     * 每天 00:01 执行
     */
    @Scheduled(cron = "0 1 0 * * ?")
    public void syncTaskListStatus() {
        // 查询近 5 分钟内的数据
        log.info("TaskListOperation syncTaskListStatus execute start");
        try {
            taskListService.updateTaskListStatus();
            log.info("TaskListOperation syncTaskListStatus execute end");
        } catch (Exception e) {
            log.error("TaskListOperation syncTaskListStatus execute fail ", e);
        }
    }
}
